package dao

import (
	"context"
)

const (
	TableUser = "user"
)

//用户表

type User struct {
	Id             int64  `json:"id" structs:"id" gorm:"primary_key;column:id;type:BIGINT(16) AUTO_INCREMENT;comment:'自增id'" sql:"auto_increment;primary_key"`
	UserId         int64  `json:"userId" structs:"user_id" gorm:"column:user_id;type:bigint(16);default:0;comment:'用户id'"`
	Name           string `json:"name" structs:"name" gorm:"column:name;type:varchar(128);default:'';comment:'名称'"`
	VisitorName    string `json:"visitorName" structs:"visitor_name" gorm:"column:visitor_name;type:varchar(128);default:'';comment:'游客名称'"`
	Avatar         string `json:"avatar" structs:"avatar" gorm:"column:avatar;type:varchar(128);default:'';comment:'头像'"`
	VisitorAvatar  string `json:"visitorAvatar" structs:"visitor_avatar" gorm:"column:visitor_avatar;type:varchar(128);default:'';comment:'游客头像'"`
	Password       string `json:"password" structs:"password" gorm:"column:password;type:varchar(64);default:'';comment:'密码'"`
	Email          string `json:"email" structs:"email" gorm:"column:email;type:varchar(64);default:'';comment:'邮箱'"`
	Mobile         string `json:"mobile" structs:"mobile" gorm:"column:mobile;type:varchar(128);default:'';comment:'手机'"`
	Status         int    `json:"status" structs:"status" gorm:"column:status;type:tinyint(1);default:1;comment:'状态 1-登录 2-登出 3-注销'"`
	Gender         int    `json:"gender" structs:"gender" gorm:"column:gender;type:tinyint(1);default:1;comment:'性别 1-男 2-女'"`
	RegistTime     int64  `json:"registTime" structs:"regist_time" gorm:"column:regist_time;type:bigint(16);default:0;comment:'注册时间'"`
	LastLoginTime  int64  `json:"lastLoginTime" structs:"last_login_time" gorm:"column:last_login_time;type:bigint(16);default:0;comment:'最近登录时间'"`
	LastLoginIp    string `json:"lastLoginIp" structs:"last_login_ip" gorm:"column:last_login_ip;type:varchar(128);default:'';comment:'最近登录ip'"`
	RegistIp       string `json:"registIp" structs:"regist_ip" gorm:"column:regist_ip;type:varchar(128);default:'';comment:'注册ip'"`
	CreateTime     int64  `json:"createTime" structs:"create_time" gorm:"column:create_time;type:bigint(16);default:0;comment:'创建时间'"`
	UpdateTime     int64  `json:"updateTime" structs:"update_time" gorm:"column:update_time;type:bigint(16);default:0;comment:'更新时间'"`
	UpUserId       int64  `json:"upUserId" structs:"up_user_id" gorm:"column:up_user_id;type:bigint(16);default:0;comment:'邀请用户id'"`
	UserType       int    `json:"userType" structs:"user_type" gorm:"column:user_type;type:tinyint(1);default:1;comment:'用户类型 1-游客 2-正常用户'"`
	DeviceId       string `json:"deviceId" structs:"device_id" gorm:"column:device_id;type:varchar(512);default:'';comment:'设备id'"`
	Brand          string `json:"brand" structs:"brand" gorm:"column:brand;type:varchar(128);default:'';comment:'手机品牌'"`
	WxaAvatar      string `json:"wxaAvatar" structs:"wxa_avatar" gorm:"column:wxa_avatar;type:varchar(256);default:'';comment:'微信头像'"`
	WxaNick        string `json:"wxaNick" structs:"wxa_nick" gorm:"column:wxa_nick;type:varchar(128);default:'';comment:'微信昵称'"`
	WxaOpenId      string `json:"wxaOpenId" structs:"wxa_open_id" gorm:"column:wxa_open_id;type:varchar(128);default:'';comment:'微信openid'"`
	WxaUnionid     string `json:"wxaUnionid" structs:"wxa_union_id" gorm:"column:wxa_union_id;type:varchar(128);default:'';comment:'微信unionid'"`
	WxaBind        int    `json:"wxaBind" structs:"wxa_bind" gorm:"column:wxa_bind;type:tinyint(1);default:0;comment:'微信绑定状态 0-未绑定 1-已绑定'"`
	MobileBind     int    `json:"mobileBind" structs:"mobile_bind" gorm:"column:mobile_bind;type:tinyint(1);default:0;comment:'手机绑定状态 0-未绑定 1-已绑定'"`
	RealRegistTime int64  `json:"realRegistTime" structs:"real_regist_time" gorm:"column:real_regist_time;type:bigint(16);default:0;comment:'实际注册时间'"`
	RealRegistIp   string `json:"realRegistIp" structs:"real_regist_ip" gorm:"column:real_regist_ip;type:varchar(128);default:'';comment:'实际注册ip'"`
	RealRegistType int    `json:"realRegistType" structs:"real_regist_type" gorm:"column:real_regist_type;type:tinyint(1);default:0;comment:'实际注册类型 0-未注册 1-手机 2-微信'"`
	Province       string `json:"province" structs:"province" gorm:"column:province;type:varchar(64);default:'';comment:'省'"`
	City           string `json:"city" structs:"city" gorm:"column:city;type:varchar(64);default:'';comment:'市'"`
	Country        string `json:"country" structs:"country" gorm:"column:country;type:varchar(64);default:'';comment:'国家'"`
	LoginProvince  string `json:"loginProvince" structs:"login_province" gorm:"column:login_province;type:varchar(64);default:'';comment:'省'"`
	LoginCity      string `json:"loginCity" structs:"login_city" gorm:"column:login_city;type:varchar(64);default:'';comment:'市'"`
	LoginCountry   string `json:"loginCountry" structs:"login_country" gorm:"column:login_country;type:varchar(64);default:'';comment:'国家'"`
	UnRegistTime   int64  `json:"unRegistTime" structs:"un_regist_time" gorm:"column:un_regist_time;type:bigint(16);default:0;comment:'注销时间'"`
	UnMobile       string `json:"unMobile" structs:"un_mobile" gorm:"column:un_mobile;type:varchar(64);default:'';comment:'注销时手机'"`
	UnWxaOpenId    string `json:"unWxaOpenId" structs:"un_wxa_open_id" gorm:"column:un_wxa_open_id;type:varchar(128);default:'';comment:'注销时微信openid'"`
	UnDeviceId     string `json:"unDeviceId" structs:"un_device_id" gorm:"column:un_device_id;type:varchar(512);default:'';comment:'注销时设备id'"`
	LastActiveTime int64  `json:"lastActiveTime" structs:"last_active_time" gorm:"column:last_active_time;type:bigint(16);default:0;comment:'最后活跃时间'"`
	IsSystemUser   int    `json:"isSystemUser" structs:"is_system_user" gorm:"column:is_system_user;type:tinyint(1);default:0;comment:'是否系统用户'"`
	First          int64  `json:"first" structs:"first" gorm:"column:first;type:bigint(16);default:0;comment:'一级注册数量'"`
	Second         int64  `json:"second" structs:"second" gorm:"column:second;type:bigint(16);default:0;comment:'二级注册数量'"`
	SUrl           string `json:"sUrl" structs:"s_url" gorm:"column:s_url;type:varchar(256);comment:'短链url'"`
	IsStoreManager int    `json:"isStoreManager" structs:"is_store_manager" gorm:"column:is_store_manager;type:tinyint(1);default:0;comment:'是否店长'"`
}

func (User) TableName() string {
	return TableUser
}

type (
	StatUserTotalItem struct {
		TotalVip      int64 `json:"totalVip"`
		TotalVisit    int64 `json:"totalVisit"`
		TotalUnbind   int64 `json:"totalUnbind"`
		TotalUnregist int64 `json:"totalUnregist"`
	}
	StatGroupUserItem struct {
		UserId int64 `json:"userId"`
		Total  int64 `json:"total"`
	}

	StatShareTotalItem struct {
		Today     int64 `json:"today"`
		Yesterday int64 `json:"yesterday"`
		Total     int64 `json:"total"`
	}
)

type IUserRepo interface {
	Add(ctx context.Context, user User) error //添加用户
	FindByParams(ctx context.Context, whereParams map[string]interface{}) (User, error)
	UpdateByParams(ctx context.Context, whereParams, updateParams map[string]interface{}) error
	ListByUserIds(ctx context.Context, userIds []int64) ([]User, int, error)
	ListUsers(ctx context.Context, memberType, mobileBind, wxaBind, status, isSystemUser int, from int64, to int64, page int, size int, sort string) ([]User, int, error)
	ListUserByParams(ctx context.Context, whereParams map[string]interface{}, page, size int) ([]User, int, error)
	ListInvite(ctx context.Context, userId int64, page, size int, startTime, endTime int64) ([]User, int, error)
	CountInvite(ctx context.Context, userId int64, startTime, endTime int64) (int, error)
	ListFirstInvite(ctx context.Context, userId int64) ([]int64, error)
	CountSecondInvite(ctx context.Context, userIds []int64) (int, error)
	GetLatestUser(ctx context.Context, whereParams map[string]interface{}) (User, error)
	IncFirstInvite(ctx context.Context, whereParams map[string]interface{}, num int64) error
	IncSecondInvite(ctx context.Context, whereParams map[string]interface{}, num int64) error
	StatTotal(ctx context.Context) (*StatUserTotalItem, error)
	StatGroupInvite(ctx context.Context, startTime, endTime int64, page, size int) ([]StatGroupUserItem, int, error)
	CountByParams(ctx context.Context, whereParams map[string]interface{}) (int, error)
	StatInviteTotal(ctx context.Context) (*StatShareTotalItem, *StatShareTotalItem, error)
}
